﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MyMainSite.Models;

namespace MyMainSite.Repositories
{
	public class DeveloperCommentRepository
	{
		#region Public Methods

		public bool AddComment(string comment, string projectName, string authorName, string authorEMailAddress)
		{
			RichardsSiteEntities context = new RichardsSiteEntities();

			if (String.IsNullOrEmpty(comment) || String.IsNullOrEmpty(projectName))
				return false;

			ProjectRepositoryImplemented projectRepo = new ProjectRepositoryImplemented();
			Project project = projectRepo.GetProjectByName(projectName);
			if (project == null)
				return false;

			DeveloperComment dc = new DeveloperComment();
			dc.Comment = comment;
			dc.ProjectId = project.ProjectId;
			dc.AuthorName = authorName;
			dc.AuthorEMailAddress = authorEMailAddress;
			dc.Date = DateTime.Now;

			context.DeveloperComments.AddObject(dc);
			context.SaveChanges();

			return true;
		}

		#endregion
	}
}